package com.sskj.level.presenter;

import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.lib.bean.PageBean;
import com.sskj.level.bean.PingCangType;
import com.sskj.level.bean.TradeListBean;
import com.sskj.level.http.HttpConfig;
import com.sskj.level.ui.fragment.DealFragment;
import com.sskj.common.base.HttpData;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.http.JsonConverter;

import java.util.List;

import io.reactivex.Flowable;


public class DealFragmentPresenter extends BasePresenter<DealFragment> {
    public Flowable<List<TradeListBean>> getTradeList(String startDate,String endDate) {
//        ArrayList<TradeListBean> tradeListBeans = new ArrayList<>();
//        for (int i = 0; i < 10; i++) {
//            tradeListBeans.add(new TradeListBean());
//        }
//        return Flowable.fromIterable(tradeListBeans)
//                .toList()
//                .toFlowable();

        return httpService.getTradeList(startDate,endDate,"2", null)
                .converter(new JsonConverter<HttpData<PageBean<TradeListBean>>>() {
                })
                .adapt(new FlowableBody<>())
                .map(pageBeanHttpData -> pageBeanHttpData.getData().getList());

    }

    public void getPingCangType() {
        httpService.getPingCangType()
                .execute(new JsonCallBack<HttpData<List<PingCangType>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<PingCangType>>> response) {
                        HttpData<List<PingCangType>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {

                        mView.setPingCangType(httpData.getData());
                        }
                    }
                });
    }
}
